home *** CD-ROM | disk | FTP | other *** search
- /* bt_top.c - find_exact, find_ins, find_del functions */
- #include "stdio.h"
- #include "btree.h"
- #include "bt_macro.h"
- extern IX_DESC *pci ;
-
- int find_exact(pe,pix) /* find entry with same key & rptr */
- ENTRY *pe ; /* put the entry here */
- IX_DESC *pix ; /* points to an index descriptor */
- {
- int ret ;
- ENTRY e ;
-
- pci = pix ;
- copy_entry(&e,pe) ; /* make copy for find call */
- ret = find_ix(&e,pix) ; /* get first entry that matches key */
-
- while( ret == 0 ) /* keep going until keys don't match */
- { if( e.rptr == pe->rptr ) /* compare rec. ptrs */
- return( 0 ) ; /* return if they match */
- /* ptrs not same - continue */
- if( get_next(&e,pix) == EOIX ) /* get next entry */
- return( 1 ) ; /* at end-of-index not found */
- ret = call(pci->pcomp) (&e,pe) ; /* compare keys */
- }
- return( ret ) ; /* not found - non-zero code */
- }
-
-
- int find_ins(pe,pix) /* find position, insert an entry */
- ENTRY *pe ; /* the entry */
- IX_DESC *pix ; /* points to an index descriptor */
- { /* returns IX_FAIL if entry present */
- int ret ;
- ENTRY tempe ;
-
- if(find_exact(pe,pix) == 0 ) /* look for the entry */
- return( IX_FAIL ) ; /* already there - failure */
- /* the find set the curr. pos */
- return(insert_ix(pe,pix)) ; /* do the insertion */
- }
-
- int find_del(pe,pix) /* find position, delete an entry */
- ENTRY *pe ; /* the entry */
- IX_DESC *pix ; /* points to an index descriptor */
- { /* returns IX_FAIL if not found */
- int ret ;
- ENTRY tempe ;
-
- if(find_exact(pe,pix) != 0 ) /* look for the entry */
- return( IX_FAIL ) ; /* not there - failure */
- /* the find set the curr. pos */
- return(delete_ix(pe,pix)) ; /* do the deletion */
-
- }
-
-
-